<template>
  <el-menu default-active="" class="el-menu-vertical-demo" :collapse="collapse" :unique-opened="true">
    <slot></slot>
    <el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path" @click="clickMenu(item)">
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <el-submenu :index="item.path" v-for="item in hasChildren" :key="item.path">
      <template slot="title">
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item :index="subitem.path" v-for="(subitem, subindex) in item.children" :key="subindex" @click="clickMenu(subitem)">
          <i :class="'el-icon-' + subitem.icon"></i>
          <span slot="title">{{ subitem.label }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: "MenuTree",
  props: {
    noChildren: Array,
    hasChildren: Array,
    collapse: Boolean
  },
  methods: {
    clickMenu(item) {
      this.$router.push(item.path);
      this.$store.commit("selectMenu", item);
    }
  }
};
</script>

<style lang="scss" scoped></style>
